
<%@ page import="com.ugoodtech.mdcc.core.domain.SystemUser" %>
<%@ page import="com.ugoodtech.mdcc.web.security.SecurityUtil" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>

<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%--<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security" %>--%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<c:set var="datePattern"><fmt:message key="date.format"/></c:set>

<script type="text/javascript">


    <%--<%User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();%>--%>
    <%SystemUser user= (SystemUser) SecurityUtil.getAuthenticatedUser();%>
    var loginId=null;
    var loginUsername=null;
    <%if (null != user) {%>
    loginId='<%=user.getUsername()%>';
    loginUsername='<%=user.getUsername()%>';
    <%}%>
    var ctx = "${pageContext.request.contextPath}";


    var userFunctionPermission = {
        <%--name:'<%=customer.getUsername()%>',--%>
        functions: [],
        hasFunction: function (n) {
            var found = false;
            var functions = this.functions;
            for (var l = 0; l < functions.length; l++) {
                if (functions[l] == n) {
                    found = true
                }
            }
            return found;
        }
    };

    <%
       List<String> roleList = new ArrayList<String>();
       if(null!=user){
           if (null!=user.getRoleNames()) {
                for(String name:user.getRoleNames()){
                    roleList.add("\""+name+"\"");
            }}

       }
       %>
    var userFunctions=<%=roleList%>;
    for (var i = 0; i < userFunctions.length; i++) {
        userFunction = userFunctions[i];
        userFunctionPermission.functions.push(userFunction);
    }


    function hasRole(funName){
        console.log(userFunctionPermission.hasFunction(funName))
        return userFunctionPermission.hasFunction(funName);
    }
</script>
<%--<link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">--%>
<link rel="shortcut icon" href="/images/icon-card.png" type="image/x-icon">
<%--<link id="TabImg" rel="shortcut icon" href="${pageContext.request.contextPath}/images/favicon.ico"/>--%>
<script id="microloader" type="text/javascript" src="${pageContext.request.contextPath}/scripts/ext5/ext/build/ext-all.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/ext5/ext/build/packages/ext-locale/build/ext-locale-en_GB.js"></script>
<script  type="text/javascript" src="${pageContext.request.contextPath}/scripts/ext5/ext/example/examples.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/scripts/ext5/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/styles/home.css" />

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/scripts/ext5/ext/example/example.css" />


<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/scripts/ext5/ext/example/example.css"/>


<html>
<body>
<div id="north-header" class="x-hide-display">
    <div class="title_bg" style="height:55px;color: white;
    font-size: 30px;
    line-height: 130%;
    font-weight: 900;" >
        正新食品
        <%if (user != null) {%>
        <%="<div class='my_account'><a id='myAccountName' class='name' " +
//                "href='eo_reset_password'" +
                ">"%>
        <%--<%=loginUserName%>--%>
        <%--<%="</a><a href='password'><div id='getSettingsButton' title='设置'>修改密码</div></a><div class='split'></div><a href='"%>--%>
        <%--${pageContext.request.contextPath}<%="/logout'><div class='logout' style='white-space: nowrap;'>登出</div></a>"%>--%>
        <%--<%}%>--%>

        <%="<div id='navigationButton' class='logout' ></div></a>"%>
        <%}%>
    </div>
    <%--<div id="navigationButton"></div>--%>
</div>

<div id="south-footer" class="x-hide-display">
    <div id="myFooter">
        <div class="footer_Text" id="myFooterText">
            <div class="footer_boldtext" id="myCareNum">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <span id="footer_CustomerCare" style="display: inline-block; color: White;width: 296px;"></span>
            </div>
            <br/>

            <div class="footerText" id='systemVerionNumber'></div>
        </div>

        <%--<div class="footer_boldtext" id="myCareNum">--%>
        <%--<span id="footer_CustomerCare" style="display: inline-block; color: White; height: 11px; width: 296px;">--%>

        <%--</span>--%>
        <%--</div>--%>
    </div>
    <div id="myCopyright" style="text-align: right">
 <span class="myCopyLeft copyright">
     <a id="copyright_CorporateName" class="copyright"> 正新食品 Co.,Ltd.</a>
     <%--&nbsp; | &nbsp;--%>
  <%--<a id="copyright_CorporateHome" class="copyright" href="">公司主页</a>--%>
  <%--&nbsp; | &nbsp;--%>
  <%--<a id="copyright_PrivacyPolicy" class="copyright" href="">隐私政策</a>--%>
 </span>
        <%--<span id="copyright_Copyright" class="myCopyRight copyright" title="">--%>
        <%--© 2011-2014 Ugood Technology,LLC.  CopyRight --%>
        <%--</span>--%>
    </div>
</div>
</body>

<script type="text/javascript">
    if (undefined != Ext.get('navigationButton')) {
        var interval = setInterval(function () {
            console.log(111);
            if (undefined != Ext.getCmp('app-main')) {
                new Ext.Button({
                    xtype: 'button',
//                  icon: ctx+'/images/options.png',
                    iconCls: 'logout-icon',
                    cls: 'pointer_btn',
                    border: 0,
                    scale: 'small',
                    press: false,
                    text: loginUsername,
                    renderTo: 'navigationButton',
                    menu: [
                        {
                            text: '修改密码',
                            handler: function () {
                                Ext.widget("passwordChange");
                            }
                        },
                        {
                            text: '登出',
                            handler: function () {
                                location.href = ctx + '/logout'
                            }
                        }
                    ]
                });
                Ext.get('navigationButton').setWidth(loginUsername.length * 8);
                clearInterval(interval);
            }
        }, 1000);
    }
    function getSystemVersion() {
        Ext.Ajax.request({
            method: "get",
            url: ctx + "/getSystemVersion",
            success: function (response) {
                var systemVersionText = "";
                systemVersionText = Ext.decode(response.responseText).data;
                document.getElementById("myFooterText").innerHTML = systemVersionText;
            }
        });
    }
    getSystemVersion();


    var appointmentCount = 0;
    var appointmentTotal = 0;
    var coopCount = 0;
    var coopTotal = 0;
    var freshAll = function () {
        freshNoConfirm();
        freshLateConfirm();
        freshSignConfirm();

    }

    var freshNoConfirm = function () {
        var params = {
            param: '',
            size: 1000,
            page: 0,
            status:'auditFailure'
        };
        Ext.Ajax.request({
            url: ctx + '/requestOrder/getFailRequestOrders',
            params: params,
            method: "get",
            success: function (response, opts) {
                //alert(response.responseText)
                var requestTotal = Ext.decode(response.responseText).total;
                Ext.getCmp('main-navigation').items.get(0).getStore().each(
                    function (record) {
                        console.log(record);
                        if (record.data.hrefView == "noConfirmGrid") {
//                                console.log(appointmentCount+"  "+appointmentTotal)
                            if (requestTotal != 0) {
                                if (record.get('text') != "审核未通过" + "<font color='red'>(" + (requestTotal) + ")</font>") {
                                    record.set("text", "审核未通过" + "<font color='red'>(" + (requestTotal) + ")</font>");
                                    Ext.getStore('NoConfirm').load();
                                }
                            } else {
                                record.set("text", "审核未通过")

                            }
                        }
                    }
                )

//                appointmentCount=total;
            },
            failure: function (response, opts) {

            }
        });


    };
    var freshLateConfirm = function () {
        var params = {
            param: '',
            size: 1000,
            page: 0
        };
        Ext.Ajax.request({
            url: ctx + '/requestOrder/getLateRequestOrders',
            params: params,
            method: "get",
            success: function (response, opts) {
                //alert(response.responseText)
                var requestTotal = Ext.decode(response.responseText).total;
                Ext.getCmp('main-navigation').items.get(0).getStore().each(
                    function (record) {
                        if (record.data.hrefView == "lateConfirmGrid") {
//                                console.log(appointmentCount+"  "+appointmentTotal)
                            if (requestTotal != 0) {
                                if (record.get('text') != "延迟申请" + "<font color='red'>(" + (requestTotal) + ")</font>") {
                                    record.set("text", "延迟申请" + "<font color='red'>(" + (requestTotal) + ")</font>");
                                    Ext.getStore('LateConfirm').load();
                                }
                            } else {
                                record.set("text", "延迟申请")

                            }
                        }
                    }
                )

//                appointmentCount=total;
            },
            failure: function (response, opts) {

            }
        });


    };
    var freshSignConfirm = function () {
        var params = {
            param: '',
            size: 1000,
            page: 0,
            status:'signed'
        };
        Ext.Ajax.request({
            url: ctx + '/requestOrder/getSignRequestOrders',
            params: params,
            method: "get",
            success: function (response, opts) {
                //alert(response.responseText)
                var requestTotal = Ext.decode(response.responseText).total;
                Ext.getCmp('main-navigation').items.get(0).getStore().each(
                    function (record) {
                        if (record.data.hrefView == "signConfirmGrid") {
//                                console.log(appointmentCount+"  "+appointmentTotal)
                            if (requestTotal != 0) {
                                if (record.get('text') != "已签约门店" + "<font color='red'>(" + (requestTotal) + ")</font>") {
                                    record.set("text", "已签约门店" + "<font color='red'>(" + (requestTotal) + ")</font>");
                                    Ext.getStore('SignConfirm').load();
                                }
                            } else {
                                record.set("text", "已签约门店")
                            }
                        }
                    }
                )

//                appointmentCount=total;
            },
            failure: function (response, opts) {

            }
        });
    };
</script>
</html>